<?php

/**
 * This is the model class for table "donation".
 *
 * The followings are the available columns in table 'donation':
 * @property integer $donation_id
 * @property string $donation_payment_method
 * @property string $donation_amount
 * @property string $donation_location
 * @property integer $donation_people_id
 *
 * The followings are the available model relations:
 * @property People $donationPeople
 */
class Donation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Donation the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'donation';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('donation_payment_method, donation_amount, donation_location, donation_people_id', 'required'),
			array('donation_people_id', 'numerical', 'integerOnly'=>true),
			array('donation_payment_method, donation_location', 'length', 'max'=>45),
			array('donation_amount', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('donation_id, donation_payment_method, donation_amount, donation_location, donation_people_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'donationPeople' => array(self::BELONGS_TO, 'People', 'donation_people_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'donation_id' => 'Donation',
			'donation_payment_method' => 'Payment Method',
			'donation_amount' => 'Amount',
			'donation_location' => 'Donation Location',
			'donation_people_id' => 'Donation People',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('donation_id',$this->donation_id);
		$criteria->compare('donation_payment_method',$this->donation_payment_method,true);
		$criteria->compare('donation_amount',$this->donation_amount,true);
		$criteria->compare('donation_location',$this->donation_location,true);
		$criteria->compare('donation_people_id',$this->donation_people_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}